import java.util.HashSet;

public class ValidSquare {

    HashSet<Integer> set = new HashSet<>();
    public boolean validSquare(int[] p1, int[] p2, int[] p3, int[] p4) {
        int[][] nums = new int[4][2];
        nums[0] = p1;
        nums[1] = p2;
        nums[2] = p3;
        nums[3] = p4;
        for (int i = 0; i < nums.length - 1; i++) {
            for (int j = i + 1; j < nums.length; j++) {
                cal(nums[i], nums[j]);
            }
        }
        return set.size() == 2 && !set.contains(0);
    }

    public void cal(int[] p1, int[] p2) {
        int x = p1[0] - p2[0];
        int y = p1[1] - p2[1];
        set.add(x * x + y * y);
    }
}
